package com.example.housekeeping.controller;

import com.example.housekeeping.pojo.dto.CommentAddNewDTO;
import com.example.housekeeping.pojo.dto.CommentUpdateDTO;
import com.example.housekeeping.pojo.entity.Comment;
import com.example.housekeeping.pojo.vo.CommentListItemVO;
import com.example.housekeeping.pojo.vo.CommentStandardVO;
import com.example.housekeeping.service.CommentService;
import com.example.housekeeping.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 评论表(Comment)表控制层
 *
 * @author bob
 * @since 2023-03-30 14:26:07
 */
@Api("03.评论管理")
@Slf4j
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("添加评论")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(CommentAddNewDTO commentAddNewDTO) {
        log.debug("开始处理【添加评论】的请求，参数：{}", commentAddNewDTO);
        commentService.addNew(commentAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除评论")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "评论id", value = "id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【根据id删除评论】的请求，参数：{}", id);
        commentService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改评论详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "评论id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateInfoById(@PathVariable Long id, CommentUpdateDTO commentUpdateDTO) {
        log.debug("开始处理【修改评论详情】的请求，参数ID：{}, 新数据：{}", id, commentUpdateDTO);
        commentService.updateById(id, commentUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "属性id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<CommentStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询属性详情】的请求，参数：{}", id);
        CommentStandardVO standardById = commentService.getStandardById(id);
        return JsonResult.ok(standardById);
    }

    @ApiOperation("查询评论列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<CommentListItemVO>> list() {
        log.debug("开始处理【评论列表】的请求，参数：{}");
        List<CommentListItemVO> list = commentService.list();
        return JsonResult.ok(list);
    }
    @ApiOperation("根据服务员查询评论列表")
    @ApiOperationSupport(order = 411)
    @ApiImplicitParam(name = "workerId", value = "服务员id",
            required = true, dataType = "long")
    @GetMapping("/list-by/{workerId:[0-9]+}")
    public JsonResult<List<CommentListItemVO>> listByWorkerId(Long workerId) {
        log.debug("开始处理【根据workerid 查询评论列表】的请求，参数：{}");
        List<CommentListItemVO> list = commentService.listByWorkerId(workerId);
        return JsonResult.ok(list);
    }

    @PostMapping("/update/{id}/disable")
    public JsonResult<Void> setNoPass(@PathVariable Long id){
        log.debug("禁用");
        commentService.setNotPass(id);
        return JsonResult.ok();
    }

    @PostMapping("/update/{id}/enable")
    public JsonResult<Void> setPass(@PathVariable Long id){
        log.debug("启用");
        commentService.setPass(id);
        return JsonResult.ok();
    }

}

